<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			let a = "  hha  sc  ";
			console.log(a.length);
			a = 123;
			if(typeof(a) !== 'string'){
				a = a.toString();
				console.log(a.length); //trim()方法只是对字符串使用
			}
			// console.log(a);
			
			let b = "这是一个电脑";
			if(b.indexOf("电脑") !== -1){ //-1表示找到
				console.log("有电脑两个字");
			}
			console.log(b.startsWith("这是"));
			console.log(b.endsWith("这是")); //用户判断文件后缀比较多
			// b.lastIndexOf();//一样的效果
			
			let c = "{name:'hh',age:20}";
			c = c.substr(1,c.length);
			console.log(c);
			c = c.substr(0,c.lastIndexOf("}"));
			console.log(c);
			
			//按,分隔
			let d = c.split(",");//返回数组
			console.log(d);
			console.log(d[0].split(":"));
			console.log(d[1].split(":"));
			
			
			let e = "          hha  scx      ".trim();
			console.log(e.length);
			// // a = 123;
			// if(typeof(e) === 'string'){
			// 	// e = e.toString();
			// 	console.log(e.length); //trim()方法只是对字符串使用
			// }
			
			function Trim(mystr){
				//去掉首部空格
				while(mystr.indexOf(" ") == 0 && mystr.length > 1){
					mystr = mystr.substring(1,mystr.length);
				}
				//去掉尾部空格
				while(mystr.lastIndexOf(" ") == (mystr.length-1) && mystr.length > 1){
					mystr = mystr.substring(0,mystr.length-1);
				}
				if(mystr == " "){
					return ";"
				}
				return mystr;
				console.log(mystr);
			}
		</script>
	</body>
</html>
